package com.gz.rocketmq.config;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
public class RocketMqConfig {

    @Value("${rocketmq.producer.nameServer}")
    private String nameSerAdd;

    @Value("${rocketmq.producer.group}")
    private String group;

    @Bean(destroyMethod = "shutdown")
    public DefaultMQProducer producer() throws MQClientException {
        DefaultMQProducer producer = new DefaultMQProducer(group);
        producer.setNamesrvAddr(nameSerAdd);
        producer.setRetryTimesWhenSendFailed(5);
        producer.start();
        log.info("==============生产者启动===========");
        return producer;
    }

}
